package com.lyq.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyq.mapper.DoctorMapper;
import com.lyq.pojo.Doctor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyq
 * @since 2020-05-08
 */
@RestController
@RequestMapping("/weixing/doctor")
public class DoctorController {
    @Autowired
    private DoctorMapper doctorMapper;

    @RequestMapping("/selectDoctorByName")
    public List<Doctor> selectDoctorByName(String doctorName){
        if(StringUtils.isEmpty(doctorName)){
            return null;
        }else{
            QueryWrapper wrapper = new QueryWrapper();

            wrapper.like("doctor_describe",doctorName);
            List<Doctor> doctorList = doctorMapper.selectList(wrapper);
            return doctorList;
        }
    }

    /**
     * 通过科室id查询医生
     * @param id
     * @return
     */
    @RequestMapping("/selectDoctorById")
    public List<Doctor> selectDoctorbyId(int id){

            QueryWrapper wrapper = new QueryWrapper();
            if(id<50) {
                wrapper.eq("did", id);
                List bydidlist = doctorMapper.selectList(wrapper);
                return bydidlist;
            }else {
                wrapper.ge("version",50);
                List bydidlist = doctorMapper.selectList(wrapper);
                return bydidlist;

            }

    }

    /**
     * 查询医生通过医生Id
     * @param doctorId
     * @return
     */
    @RequestMapping("/selectDoctorByDoctorId")
    public Doctor selectDoctorByDoctorId(int doctorId){
        Doctor doctor = doctorMapper.selectById(doctorId);
        return doctor;
    }
    @RequestMapping("/selectDoctorhIdanddid")
    public List<Doctor> selectDoctorhIdanddid(int did,int hid){
        Map<String,Object> map = new HashMap<>();
        map.put("did",did);
        map.put("hid",hid);
        List<Doctor> doctors = doctorMapper.selectByMap(map);
        System.out.println(doctors);
        return doctors;

    }

}

